package com.project.shangqi.service.impl;

import com.project.shangqi.dto.VehicleResult;
import com.project.shangqi.entity.VehicleInfo;
import com.project.shangqi.mapper.VehicleInfoMapper;
import com.project.shangqi.service.VehicleInfoService;
import com.project.shangqi.util.HttpUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class VehicleInfoServiceImpl implements VehicleInfoService {

    @Resource
    private VehicleInfoMapper vehicleInfoMapper;

    @Override
    public VehicleResult getFromUrl(String token, String url, Integer timeout) throws Exception {
        HttpUtil httpUtil = new HttpUtil(url, token, timeout);
        VehicleResult result = (VehicleResult) httpUtil.getUrl(VehicleResult.class, 1);
        return result;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insert(VehicleInfo entity) throws Exception {
        vehicleInfoMapper.insertSelective(entity);
    }
}
